<?php

namespace Yolo\Components\Scheduler\Observers;

use Yolo\Components\Scheduler\SchedulerManager;
use Yolo\Di\DI;
use Yolo\Observers\ObserverInterface;
use Yolo\Service\Subjects\AfterWorkerStartedSubject;

class AfterWorkerStartedObserver implements ObserverInterface
{
    public function __construct(
        private readonly SchedulerManager $schedulerManager
    ) {}

    /**
     * The list of events this observer is listening to.
     * @return string[]
     */
    public function listens(): array
    {
        return [
            AfterWorkerStartedSubject::class,
        ];
    }

    public function process(string $event, array $data): void
    {
        // 放到后台去跑，防止阻塞
        \Hyperf\Coroutine\go(function () {

            $this->schedulerManager->start();
        });
    }
}